import { Observable } from './Observable'
/**
 * 接收taget目标对象，和事件名称返回Observable，并且Subseriber上挂载unsubscribe()取消监听
 * @param target Document ｜Window
 * @param e EventHandleType
 * @returns Observable
 */
export function fromEvent(target: Document | Window, e: string) {
  return new Observable((subscribe => {
    const handler = (...args: any[]) => subscribe.next(...args)
    target.addEventListener(e, handler)
    return () => target.removeEventListener(e, handler)
  }))
}